//
//  MineViewController.m
//  TriumphInTheSkiesAPP
//
//  Created by 要帅气的生活 on 15/11/3.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "MineViewController.h"
#import "MFJNight.h"
#import "Size.h"
#import "ToolUtil.h"
#import "ImageUtil.h"
#import "EntityUtil.h"
#import "CollectionViewController.h"
#import "EarnViewController.h"
#import "LoginViewController.h"
#import "CustomServeViewController.h"
#import "PublicNumberViewController.h"
#import "SettingViewController.h"
#import "AreaViewController.h"
@interface MineViewController ()
@property (nonatomic, strong)UIScrollView * scrollView;

@end

@implementation MineViewController
//- (void)navigationController:(UINavigationController *)navigationController
//       didShowViewController:(UIViewController *)viewController
//                    animated:(BOOL)animated
//{
//    if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//        navigationController.interactivePopGestureRecognizer.enabled = YES;
//    }
//    NSLog(@"jkljklj");
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    [ToolUtil createLine:margin_64 superView:self.view lift:0 width:WindowWidth hight:0.5 color:[UIColor grayColor]];
    self.navigationController.navigationBar.hidden = YES;
    [self createTitle:@"" midTitle:@"我"];
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 70, WindowWidth, WindowHeight - 70)];
    _scrollView.bounces = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.backgroundColor = [UIColor whiteColor];
    [self createPhoto];
    [self.view addSubview:_scrollView];
    
    UIButton * Button = [UIButton buttonWithType:UIButtonTypeCustom];
    Button.frame = CGRectMake(250, 350, 50, 50);
    Button.backgroundColor = [UIColor blackColor];
    
    [Button addTarget:self action:@selector(doLineButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    Button.tag = 400;
    [self.scrollView addSubview:Button];
    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 350, 150, 150)];
//    imageView.backgroundColor = DEBUG_CLOLR;
    imageView.tag = 120;
    imageView.image = [UIImage imageNamed:@"lunbotu1.jpg"];
    [self.scrollView addSubview:imageView];
    NSDictionary * dataDic = @{@"titles":@[@"我的收藏",@"财富攻略",@"联系客服",@"微信公众号",@"我的资料"],
                               @"margins":@"0,0,0,0",
                               @"lineTops":@"0,0,0,0",
                               @"bottomShorts":@"0,0,0,0",
                               @"icons":@[@"lunbotu1",@"lunbotu1",@"lunbotu1",@"lunbotu1"]
                               };
    NSDictionary * dic = [self createLineButton:_scrollView dataDic:dataDic last_y:70];
    _scrollView.contentSize = CGSizeMake(0, [dic[@"last_y"] floatValue]);
    
    // Do any additional setup after loading the view.
}
- (void)createPhoto
{
    UIButton * photoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    photoButton.frame = CGRectMake(0, 0, WindowWidth, 50);
    photoButton.backgroundColor = [UIColor whiteColor];
    
    [photoButton addTarget:self action:@selector(doLineButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    photoButton.tag = 1007;
    UIImageView * photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 30, 40)];
//    photoImageView.image = [UIImage imageNamed:@"lunbotu1"];
    photoImageView.backgroundColor = [UIColor whiteColor];
    [photoButton addSubview:photoImageView];
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(photoImageView.frame ) + 10, 10, margin_110, 30)];
    label.text = @"您还未登录哦";
    label.font = FONT(15);
    [photoButton addSubview:label];
    float button_h = title_height + 3;
    
    int arrow_h = button_h * 0.36, arrow_w = arrow_h * 0.57, arrow_y = (button_h - arrow_h) / 2, arrow_x = WindowWidth - arrow_w - 10;
    UIImageView *arrow = [[UIImageView alloc] initWithFrame:CGRectMake(arrow_x, arrow_y, arrow_w, arrow_h)];
    arrow.image = [UIImage imageNamed:@"ico_arrow"];

//        UIImageView *arrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ico_arrow"]];
//    
//    arrow.frame = CGRectMake(arrow_x, arrow_y, arrow_w, arrow_h);
    [photoButton addSubview:arrow];

    
    [self.scrollView addSubview:photoButton];
//    [self.scrollView addSubview:photoImageView];
}
- (void)doLineButtonClick:(UIButton*)btn
{
    if (btn.tag == 1000) {
        NSLog(@"1");
        MFJNight *njght = [MFJNight defaultNight];
        if (njght.nightKey) {
            NSLog(@"登入状态");
            LoginViewController *login = [[LoginViewController alloc] init];
            [self.navigationController pushViewController:login animated:YES];
            login.view.backgroundColor = [UIColor whiteColor];
        }else{
            CollectionViewController *collection = [[CollectionViewController alloc] init];
            [self.navigationController pushViewController:collection animated:YES];
            collection.view.backgroundColor = [UIColor whiteColor];
        }
    }else if (btn.tag == 1001){
        NSLog(@"2");
        [self jump:@"" to:[[EarnViewController alloc] init]];
    }else if (btn.tag == 1002){
        [self jump:@"" to:[[CustomServeViewController alloc] init]];
    }else if (btn.tag == 1003){
        [self jump:@"" to:[[PublicNumberViewController alloc] init]];
    }else if (btn.tag == 1004){
        NSLog(@"5");
//        [self requestTck:<#(NSString *)#> _param:<#(NSString *)#> _callback:<#^(NSMutableDictionary *)callback#> loading_type:<#(LoadingType)#> is_backup:<#(BOOL)#> is_solveFail:<#(BOOL)#> _frequency:<#(int)#>]
        [self showUploadImg:[EntityUtil getUploadParam:200 isUpload:YES]];
        
    }else if (btn.tag == 1005){
        
    }else if (btn.tag == 1007){
        [self jump:@"" to:[[LoginViewController alloc]init]];
        NSLog(@"6");
    }else if (btn.tag == 300){
        NSLog(@"7");
        [self jump:@"" to:[[SettingViewController alloc] init]];
    }else if (btn.tag == 400){
        [self jump:@"" to:[[AreaViewController alloc]init]];
    }
}
- (void)uploadImageAfter:(id)object
{
    UIImageView * imageView = [self.view viewWithTag:120];
    imageView.image = object;
//    NSLog(@"%@",object);
}


@end
